package ZZ_backup;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeMap;

import LawsonTransformJava.dao.DAOFactoryAccessDB;

public class XrefJobCode2 {

	private final static String TABLE_NAME = "xJOBCODE";
	static final String XLATE_ERROR = "ERROR";
	
	DAOFactoryAccessDB xref = new DAOFactoryAccessDB();
	Statement stmt = null;
	ResultSet rslt = null;
	TreeMap jobcodes = new TreeMap();
	
	public XrefJobCode2() {
		try {
			stmt = xref.getStatement();
			rslt = stmt.executeQuery("SELECT * FROM " + TABLE_NAME);
			while (rslt.next()) {
				String oldjobcode = rslt.getString(1);
				String newjobcode = rslt.getString(2);
				//           <--OldJobcode--->  <--NewJobcode--->
				jobcodes.put("\"" + oldjobcode + "\"", newjobcode);
			}
		  } catch (SQLException e) {
			  // Could not connect to the database
			  System.out.println("SQLException: " + e);
		  }
	}
	
	public String xlate(String jobcode) {
		String newjobcode = (String)jobcodes.get(jobcode);
	return (newjobcode==null?XLATE_ERROR:newjobcode);
	}
}
